﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Common.Library;
using System.ComponentModel;
using OnlineVideos.Data;
using OnlineVideos.Entities;

namespace OnlineVideos
{
    public partial class VideoGameGallery : UserControl
    {  
        #region GlobalDeclaration
        private bool IsDataLoaded;
        List<VideoGameProperties> ShowVehicleList = null;
        #endregion
        public VideoGameGallery()
        {
            InitializeComponent();
            ShowVehicleList = new List<VideoGameProperties>();
            IsDataLoaded = false;
        }

        private void lbxgallery_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (IsDataLoaded == false)
            {
                MyProgressBar1.IsIndeterminate = true;
                GetPageDataInBackground();
                IsDataLoaded = true;
            }
        }
        private void GetPageDataInBackground()
        {
            BackgroundHelper bwHelper = new BackgroundHelper();

            bwHelper.AddBackgroundTask(
                                        (object s, DoWorkEventArgs a) =>
                                        {
                                            a.Result = OnlineShow.GetVehicleList(AppSettings.ShowUniqueID);
                                        },
                                        (object s, RunWorkerCompletedEventArgs a) =>
                                        {
                                            ShowVehicleList = (List<VideoGameProperties>)a.Result;
                                            if (ShowVehicleList.Count > 0)
                                            {
                                                lbxgallery.ItemsSource = ShowVehicleList;
                                                tblkgallery.Visibility = Visibility.Collapsed;
                                            }
                                            else
                                            {
                                                //tblkcontrols.Text = "No Vehicles available";
                                                tblkgallery.Visibility = Visibility.Visible;
                                            }
                                            MyProgressBar1.IsIndeterminate = false;
                                        }
                                      );
            bwHelper.RunBackgroundWorkers();
        }
    }
}
